﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace OpenPms.Migrations
{
    /// <inheritdoc />
    public partial class t204 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Guests_Orders_OrderId",
                table: "Guests");

            migrationBuilder.DropIndex(
                name: "IX_Guests_OrderId",
                table: "Guests");

            migrationBuilder.AddColumn<Guid>(
                name: "TOrderId",
                table: "Guests",
                type: "uniqueidentifier",
                nullable: true)
                .Annotation("SqlServer:IsTemporal", true)
                .Annotation("SqlServer:TemporalHistoryTableName", "GuestsHistory")
                .Annotation("SqlServer:TemporalHistoryTableSchema", null)
                .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
                .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");

            migrationBuilder.CreateIndex(
                name: "IX_Guests_TOrderId",
                table: "Guests",
                column: "TOrderId");

            migrationBuilder.AddForeignKey(
                name: "FK_Guests_Orders_TOrderId",
                table: "Guests",
                column: "TOrderId",
                principalTable: "Orders",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Guests_Orders_TOrderId",
                table: "Guests");

            migrationBuilder.DropIndex(
                name: "IX_Guests_TOrderId",
                table: "Guests");

            migrationBuilder.DropColumn(
                name: "TOrderId",
                table: "Guests")
                .Annotation("SqlServer:IsTemporal", true)
                .Annotation("SqlServer:TemporalHistoryTableName", "GuestsHistory")
                .Annotation("SqlServer:TemporalHistoryTableSchema", null)
                .Annotation("SqlServer:TemporalPeriodEndColumnName", "PeriodEnd")
                .Annotation("SqlServer:TemporalPeriodStartColumnName", "PeriodStart");

            migrationBuilder.CreateIndex(
                name: "IX_Guests_OrderId",
                table: "Guests",
                column: "OrderId");

            migrationBuilder.AddForeignKey(
                name: "FK_Guests_Orders_OrderId",
                table: "Guests",
                column: "OrderId",
                principalTable: "Orders",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
